﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>冠军竞猜 </title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/qmsk-1.2.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="shadowbox/shadowbox.js"></script>
<link href="shadowbox/shadowbox.css" rel="stylesheet" />
<link rel="stylesheet" href="../css/default.css" />
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
<script type="text/javascript" src="../js/teamSelecterNew.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<style type="text/css">
#window_change p label span img {
	border: 1px solid #CCCCCC;
	height: 90px;
	vertical-align: middle;
	width: 70px;
}
</style>
<script type="text/javascript">
	$(function() {
		 _htmlUploadUrl="apply";
		 _indexUrl="indexUrl";
		 _htmlTitle='title';
		browse('uupload','imgSrc',100,150);
	});
	$(function() {
		initImage()
	})



	function popPoint(id) {
		art.dialog({
			fixed : true,
			lock : true,
			content : "确认删除该条数据？",
			icon : 'question',
			ok : function() {
				deleteInfo(id)
			},
			cancel : true
		});
	}
	//查询
	function searchApply() {
		getTryDriverList(1);
	}
	function getTryDriverList(index) {
		if (IsEmpty(index)) {
			index = 1
		}
		var teamId = $("#teamId").val();
		var name = $("#name").val();
		var mp = $("#mp").val();
		if(IsEmpty(teamId)){
			teamId="";
		}
		var params = {
			'teamId' : teamId,
			'name':name,
			'mp':mp
		}
		var dt = _findInfo("../teamGuess/find/teamGuessList/" + (index - 1) + "/10",
				params);
		if (IsNotEmpty(dt) && dt.state == 0) {
			$("#memberList tbody").empty()

			for ( var i = 0; i < dt.result.data.length; i++) {
				var htm = "<tr>"
					htm += "<td>" + _getStringOfJson(i, dt, "customerName") + "</td>"
				htm += "<td>"
						+ _getStringOfJson(i, dt, "mp") + "</td>"
						htm += "<td>" + _getStringOfJson(i, dt, "team") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "createdTime") + "</td>"
				var id = _getIntOfJson(i, dt, "id")
				/* htm += "<td> <input type='button' class='common_btn' value='设置' class='btn' onclick='setting("
						+ id + ")'>&nbsp;<input class=\"del\" type=\"button\" onclick=\"lookInfo("+id+")\" value=\"查看竞猜\"><input class=\"del\" type=\"button\" onclick=\"delApply("+id+")\" value=\"删除\"> </td>"
		 */		htm += "</tr>"
				$("#memberList tbody").append(htm)
			}
			/* 		_loadInfo(dt, "memberList", param)
			 */
			$("#memberList tbody tr").each(function() {

			})
			_loadPage("pager", index, 10, dt, getTryDriverList, "NoResult");
			$("#sup").html("共" + dt.result.len + "条");
		}
	}

	//改变女主播
	function setting(id) {
		resForm();
		var url = " ../teamPicture/find/applyById";
		$("#upid").val(id);
		$("#doflag").val(2)
		if (id > 0) {
			$.get(url, {
				"id" : id
			}, function(g) {
				var rst = JSON.parse(g);
				console.log(rst);
				$("#imageUrl").val(_getStringOfJson(0, rst, 'imageUrl'));
				$("#imgSrc img").attr("src",_getStringOfJson(0, rst, "imageUrl"))
				$("#participation").val(_getStringOfJson(0, rst, 'status'));
				$("#name").val(_getStringOfJson(0, rst, 'name'));
				$("#result").val(_getStringOfJson(0, rst, 'resultYear'));
			});
			
			$("#yinying1,#window_change").show();
			addMargin($("#window_change"));

		}
	}
	
	function save(){
		var doflag= $("#doflag").val()
		if(doflag==1){
			insertApply()
		}else{
			updateApply()
			}
	}
//更新
	function updateApply() {
		var upid = $("#upid").val();
		var name=$("#name").val();		
		var result=$("#result").val();
		var uparticipation=$("#participation").val();		
		var heads = new Array("name","resultYear","status","id");
		var datas = new Array(name,result, uparticipation,upid);

		var parser = new Object();
		var jsonParserStr = null;//定义空头字符串
		if (IsNotEmpty(datas)) {
			addToParser(heads, datas, "edit", parser);
			jsonParserStr = JSON.stringify(parser);
		}

		var url = " ../teamPicture/edit";
		$.post(url, {
			"data" : jsonParserStr
		}, function(data) {
			$("#close_this").attr("disabled", false);
			var dt = JSON.parse(data);
			if(dt.result>0){
				 var n = upload($("#upid").val());
				$("#window_change").hide();
				searchApply();
				if(n==0){
					
				art.dialog({fixed:true, lock: true,content:'修改成功',icon:'succeed',ok:true});
				}else{
					art.dialog({fixed:true, lock: true,content:'图片出错，请在修改也重新上传',icon:'error',ok:true});
				}
				$("#yinying1").hide();
			}else{
				art.dialog({fixed:true, lock: true,content:'修改失败',icon:'error',ok:true});
			}
			console.log(data);
			//saveOwnShopIds();
			
		});

	}
	 function upload(id){
		 var n =0;
		 var fil = $("#uupload").val();
		 if(IsEmpty(fil)){
			 return n = 0;
		 }
		 
		$.ajaxFileUpload({
				url :"../teamPicture/upload/image/"+id, 
				secureuri : false,
				fileElementId : 'uupload',
				dataType : 'json',
				success : function(data){
					if($("#uupload").val()==''){
					}else{
					//alert("上传文件不为空")
					
					if(IsEmpty(data)){
/* 						art.dialog({fixed:false, lock: true,content:"上传图片出错",icon:'error',ok:true});
 */					
						n = 1;
 						return false;
						}
						if(data.state==0){
							
/* 							art.dialog({fixed:false, lock: true,content:"操作成功",icon:'succeed',ok:true});
 */							/*  $("#window_change").hide();
								$("#yinying1").hide();
								searchApply(); */
								browse('uupload','imgSrc',100,150);
								searchApply()
							return false;

						}else if(data.state==1){
/* 							art.dialog({fixed:false, lock: true,content:"保存图片出错,请重新上传图片",icon:'error',ok:true});	
 * 							n-=
 */
 		n=1;				
 			return false;
						}
					}
						
				},
				error : function(data) {
					art.dialog({fixed:true, lock: true,content:'上传图片失败',icon:'error',ok:true});	
					n=1;				
		 			return false;
		 			}
			});
		return n;
		}
	 
	
	
	//删除
	function delApply(id){
		var url = " ../teamPicture/del";
		//$("#upid").val(id);
		if (id > 0) {
			$.get(url, {
				"id" : id
			}, function(g) {
				console.log(g);
				var rst = JSON.parse(g);
				if(rst.state==0){
					searchApply();
					art.dialog({fixed:true, lock: true,content:'删除成功',icon:'success',ok:true});
				}
				console.log(rst);
				//$("#Name").val(_getStringOfJson(0, rst, 'name'))
			});
		}
	}
	function showInsert(){
		$("#window_add").show();
		addMargin($("#window_add"));
	}
	
	function resForm(){
		$("#aName").val("");
		$("#name").val("");
		$("#resultYear").val("");
		$("#imageUrl").val("");
		$("#imgSrc").val("");
		$("#indexUrl").val("");
		$("#uupload").val("");
		
	}
	
	
	function toAdd(){
		var teamId = $("#teamId").val();
		var name = $("#name").val();
		var mp = $("#mp").val();
		if(IsEmpty(teamId)){
			teamId="";
		}
		var params = {
			'teamId' : teamId,
			'name':name,
			'mp':mp
		}
		window.location.href="../teamGuess/export/csv?"+$.param(params);
		/* resForm();
		$("#doflag").val(1)
		$("#window_change,#yinying1").show();
		addMargin($("#window_change")); */
	}
	
	function insertApply(){
		var uparticipation=$("#participation").val();		
		var name=$("#name").val();		
		var result=$("#result").val();		
		var heads = new Array("status","name","resultYear");
		var datas = new Array( uparticipation,name,result);
		var parser = new Object();

		var jsonParserStr = null;//定义空头字符串
		if (IsNotEmpty(datas)) {
			addToParser(heads, datas, "add", parser);
			jsonParserStr = JSON.stringify(parser);
		}
		 var fil = $("#uupload").val();

		 if(IsEmpty(fil)){
			 alertErrorMessage("请选择照片");
			 return false
		 }
		
		$("#close_this").attr("disabled", true);
		var url = " ../teamPicture/insert";
		$.post(url, {
			"data" : jsonParserStr
		}, function(data) {
			$("#close_this").attr("disabled", false);
			var dt = JSON.parse(data);
			//alert(dt.result)
			if(dt.state==0){
				var id = getHeadIndexValue(0, dt, "id");
				 $("#window_change").hide();
				$("#yinying1").hide();
				var rnresult = upload(id);
				searchApply();
				if(rnresult==0){
				art.dialog({fixed:true, lock: true,content:'添加成功',icon:'success',ok:true});
				}else{
					art.dialog({fixed:true, lock: true,content:'图片出错，请在修改也重新上传',icon:'error',ok:true});
				}
			}else{
				art.dialog({fixed:true, lock: true,content:'添加失败',icon:'error',ok:true});
			}
			//saveOwnShopIds();
		});

	}
	/* function openImage(id){
		window.location.href=id;
		
	} */
	function initImage() {
		Shadowbox.init();
		window.openImage = function(url) {
			Shadowbox.open({
				content : url,
				player : 'img'
			});
		};
	}
	
	/* function getHtmlUrl(html) {
		var url = '';
		$.ajax({
			type : "post",
			async : false,
			datatype : "JSON",
			url : "../htmlUtils/htmlFileGender",
			data : {
				'html' : html
			},
			success : function(rst) {
				if ( typeof rst === "string") {
					rst = JSON.parse(rst);
				}
				var response = new qmsk.Response(rst);
				url = response.getValue("url");
			}
		});
		return url;
	}

	function generateHtmlUrl() {
		var html = editorHtml;
		var url = '';
		if (qmsk.isNotEmpty(html)) {
			url = getHtmlUrl(html);
		}
		alert(url);
	}
 */
	
 function lookInfo(pid){
	 pId = pid
	 $("#guess").hide()
	 $("#guessResult").show()
	 getGuessResultList(1)
 }
 
	function getGuessResultList(sdf) {
		if (IsEmpty(sdf)) {
			index2 = 1
		}else{
			index2 = sdf
		}
		var params = {
			'pid':pId
		}
		var dt = _findInfo("../teamPictureRecord/find/teamPictureRecordList/" + (index2 - 1) + "/10",
				params);
		if (IsNotEmpty(dt) && dt.state == 0) {
			$("#resultList tbody").empty()

			for ( var i = 0; i < dt.result.data.length; i++) {
				var htm = "<tr>"
				htm += "<td>" + _getStringOfJson(i, dt, "createdTime") + "</td>"
				var CustomerName = _getSomeOfJson(i, dt, "CustomerName");
				if(IsEmpty(CustomerName)){
					CustomerName = '关注客户'
				}
				htm += "<td> "+CustomerName+"</td>"
				htm += "<td>" + _getStringOfJson(i, dt, "Mp") + "</td>"
				htm += "<td>" + _getStringOfJson(i, dt, "team") + "</td>"
				htm += "<td>" + _getStringOfJson(i, dt, "staName") + "</td>"
				var id = _getIntOfJson(i, dt, "id")
				var state = _getIntOfJson(i, dt, "status");
				if(state==0){
					
				htm += "<td> <input type='button' class='common_btn' value='送积分' class='btn' onclick='showSjf("+ id + ")'> </td>"
				}else{
					htm += "<td> </td>"
				}
				htm += "</tr>"
				$("#resultList tbody").append(htm)
			}
			/* 		_loadInfo(dt, "memberList", param)
			 */
			
			_loadPage("pager2", index2, 10, dt, getTryDriverList, "NoResult2");
			$("#sup2").html("共" + dt.result.len + "条");
		}
	}
	
	
	function showSjf(id){
		art.dialog({fixed:true, lock: true,content:"确认给该用户赠送积分？",icon:'question',ok: function(){ sendInget(id) },cancel:true});
		}
	function sendInget(id){
		
		var dt = _insertInfo("../teamPictureRecord/check", {'id':id})
		if(IsNotEmpty(dt)&&dt.state==0){
			getGuessResultList(index2)
		}
	}
	
	function goBack(){
		 $("#guess").show()
		 $("#guessResult").hide()
	
	}
</script>
</head>

<body>
<div id="yinying1"></div>
	
	<div class="container" id="container">
		<div class="container_R fr" id="guess">
			<div class="place">冠军竞猜</div>
			<div class="member_search">

				<p>
				<span>用户姓名：</span>
<strong class="mainAbsolute">
<input id="name" class="absoluteTxt" type="text">
</strong>
<span>手机号：</span>
<strong class="mainAbsolute">
<input id="mp" class="absoluteTxt" type="text">
</strong>
					<span>状态：</span>
				<select id="teamId"  onclick="openTeamListPanel('teamId')" >
				
						
				 </select>
				 </p><p>
					<input type="button" style="float: right;"  value="查询" class="btn" onclick="searchApply()">
				</p>
				
			</div>

			<table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
				<caption>
					<strong>冠军竞猜列表 <span id="sup">共0条</span>
					</strong> 
										 					<input type="button" value="导出" class="common_btn addList" onclick="toAdd()">
				</caption>
				<thead>
					<tr>
						<th >姓名</th>
						<th >电话</th>
						<th >竞猜球队</th>
						<th >竞猜时间</th>
						<th >操作</th>
						
					</tr>
				</thead>
				<tbody>

				</tbody>
			</table>
			<div id="NoResult" class="Nothing"
				style="text-align: center; display: none;">无符合条件的数据！</div>
			<div id="pager" style="float: right;"></div>
		</div>
		
		
		<div class="container_R fr" style="display: none;" id="guessResult">
			<div class="place">
							<span>
				竞猜结果
				<a class="goHome" href="javaScript:void(0)" onclick="goBack()">返回</a>
				</span>
			</div>
			<div class="member_search">

		
				
			</div>

			<table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="resultList">
				<caption>
					<strong>竞猜结果列表 <span id="sup2">共0条</span>
					</strong> 
				</caption>
				<thead>
					<tr>
						<th >竞猜时间</th>
						<th >客户姓名</th>
						<th>电话</th>
						<th>竞猜内容</th>
						<th>竞猜结果</th>
						<th >操作</th>
						
					</tr>
				</thead>
				<tbody>

				</tbody>
			</table>
			<div id="NoResult2" class="Nothing"
				style="text-align: center; display: none;">无符合条件的数据！</div>
			<div id="pager2" style="float: right;" class="shopPager"></div>
		</div>
		<div class="fc"></div>
	</div>
	<!-- InstanceEndEditable -->
	<script type="text/javascript" src="../js/header.js"></script>
	<script type="text/javascript" src="../js/left.js"></script>
	<script type="text/javascript" src="../js/footer.js"></script>
	<script type="text/javascript" src="../js/ajaxfileupload.js"></script> 
	<script type="text/javascript" src="../js/ImageBrowsing.js"></script> 
	<script charset="utf-8" src="../js/kindeditor.js"></script>
	<script type="text/javascript" src="../js/editor2.js"></script>
	
	<script type="text/javascript">
		clearThis("absoluteTxt");
		showTab(1, 1);
	</script>
</body>
<!-- InstanceEnd -->
</html>
